package com.foreknow.elmboot.service.impl;

import com.foreknow.elmboot.mapper.CartMapper;
import com.foreknow.elmboot.po.Cart;
import com.foreknow.elmboot.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public int saveCart(Integer foodId, Integer businessId, Integer userId) throws Exception {
        int cart = cartMapper.saveCart(foodId,businessId,userId);
        if (cart!=0){
            cart = this.selectCartId(foodId,businessId,userId);
        }
        return cart;
    }

    @Override
    public int updateCart(Integer foodId, Integer businessId, Integer userId, Integer quantity) throws Exception {
        return cartMapper.updateCart(foodId,businessId,userId,quantity);
    }

    @Override
    public List<Cart> listCart(Integer businessId, Integer userId) throws Exception {
        return cartMapper.listCart(businessId,userId);
    }

    @Override
    public int deleteCart(Integer cartId) throws Exception {
        return cartMapper.deleteCart(cartId);
    }

    @Override
    public int selectCartId(Integer foodId, Integer businessId, Integer userId) throws Exception {
        return cartMapper.selectCartId(foodId,businessId,userId);
    }
}
